package com.atguigu.gulimall.cart.config;

import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * SpringSession配置
 *
 * @author DuGuanghan
 * @since 2024-09-11 17:31:39
 */
@Configuration
public class MySessionConfig {
    @Bean
    public CookieSerializer cookieSerializer() {
        DefaultCookieSerializer serializer = new DefaultCookieSerializer();
        // 设置Session的名称
        serializer.setCookieName("JSESSIONID");
        // 设置Session的作用域
        serializer.setDomainName("gulimall.com");

        return serializer;
    }

    /**
     * 自定义序列化器
     *
     * @return {@link RedisSerializer }<{@link Object }>
     * @author DuGuanghan
     * @since 2024-09-12 09:48:10
     */
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
        return new GenericFastJsonRedisSerializer();
    }
}
